package com.wf.it.common.util;

import java.time.LocalDate;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.Date;

public class DateUtil {
    //计算两个日期的天数差
    public static int daydiff(Date end, Date start){
        //将日期转成LocalDate对象(java8新日期类型，它方便进行运算)
        LocalDate localEnd = end.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
        LocalDate localStart = start.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
        //利用工具方法直接算出日期差
        return (int) ChronoUnit.DAYS.between(localStart, localEnd);
    }
}
